﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DrivingCRM.Controller;

namespace DrivingCRM.Views.Private.Forum
{
    public partial class ListPosts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            


        }
        protected void DS_Posts_Selecting(object sender, EntityDataSourceSelectingEventArgs e)
        {
                //((EntityDataSource)sender).SelectParameters["IdDiscussion"].DefaultValue = Request.QueryString["id"];
                e.DataSource.WhereParameters["IdDiscussion"].DefaultValue = Request.QueryString["id"];
        }
        protected void InsertPost_Clicked(object sender, EventArgs e)
        {
                MembershipUser u = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                Guid mon_id = ((Guid)u.ProviderUserKey); // ID du User connecté

                string ret = EntityManager.AddPost(this.TextBox_title.Text, this.RadEditor_Post.Text, DateTime.Now, int.Parse(Request.QueryString["id"]), mon_id);
                if (ret == "No error")
                    this.L_ErrorMessage.Text = "Le nouvel article a correctement été ajouté";
                else
                    this.L_ErrorMessage.Text = "Une erreur est survenue lors de l'ajout d'un article, veuillez saisir les champs requis.";
        
        }

    }
}